package com.secondGroup.controller;


import com.secondGroup.entity.User;
import com.secondGroup.service.QryEleBalanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.math.BigDecimal;

/**
 * @author:cyy
 * @date: 2022/05/05
 * content:查询电子账户上的余额
 */
@Controller
@RequestMapping("/qry")
public class QryEleBalanceController {

    @Autowired
    QryEleBalanceService qryEleBalanceService;

    @RequestMapping("/QryEleBalance")
    //id用户的唯一标识，eId电子账户的唯一标识
    public String getQryEleBalance(HttpServletRequest request, Model model) {
//        User userInfo = new User();
//        userInfo.setAccount("scc");
//        userInfo.setId(21);
//        userInfo.setEId("666666");
//        HttpSession session = request.getSession();
//        Object obj = session.getAttribute("userInfo");
//        System.out.println(obj);
//        User Info= (User)session.getAttribute("userInfo");
        User Info = (User) request.getSession().getAttribute("userInfo");
        Integer id = Info.getId();
        String eId = Info.getEId();
        BigDecimal eMoney = qryEleBalanceService.selectEleBalance(id, eId);
        //return eMoney;
        model.addAttribute("eMoney", eMoney);
        return "QryEleBalance";
    }
}

